home *** CD-ROM | disk | FTP | other *** search
- /*
- * RaiskaaHTML.rexx -- Usable frontend to TodellakinRaiskaaHTML.
- *
- * RaiskaaHTML strips all sorts of junk from HTML documents. As it only
- * works on pipes and has a Unix-compatible bullshit syntax, this ARexx
- * script provides a more reasonable way of using it.
- *
- * Updates are available from aminet:comm/www/RaiskaaHTML.lha
- *
- * Copyright © 1998 by Thomas Aglassinger <agi@sbox.tu-graz.ac.at>
- */
- /* $VER: RaiskaaHTML.rexx 1.0 (24.9.98) */
- release_version = '1.0'
- release_date = '24.9.98'
-
- /* Initialization */
- Options Results
- Parse Arg arguments
- Failat 6
-
- /* Add libraries. No error checking because the AddLib() return code sucks */
- Call AddLib('rexxsupport.library', 0, -30, 0)
- Call AddLib('rexxdossupport.library', 0, -30, 2)
-
- /* Support filenames */
- temporary_filename = 't:RaiskaaHTML-' || Pragma('ID') || '.temporary'
- error_filename = 't:RaiskaaHTML-' || Pragma('ID') || '.error'
- list_filename = 't:RaiskaaHTML-' || Pragma('ID') || '.list'
-
- return_code = 0
-
- /* Initilize arguments */
- template_1 = 'From/A,To/K'
- template_2 = 'Blink/S,Color/S,DocType/S,Font/S,Heading/S,Link/S,Meta/S,Quiet/S,Ruler/S,ScMsg/S,Script/S,SGML/S,Space/S,Table/S,Toggle/S'
- template = template_1 || ',' || template_2
- from = ''
- to = ''
-
- Blink = 0
- Color = 0
- DocType = 0
- Font = 0
- SGML = 0
- Heading = 0
- Link = 0
- Meta = 0
- Space = 0
- Ruler = 0
- Script = 0
- Table = 0
-
- /* Previous length of status messages */
- status_length = 0
-
- /* Constants */
- error_in_arguments = 'error in arguments: '
-
- /* Parse arguments */
- if ~ReadArgs(arguments,template) then do
- Say error_in_arguments || Fault(RC)
- Exit 10
- end
-
- /* Toggle options if requested */
- if Toggle then do
- Blink = ~Blink
- Color = ~Color
- DocType = ~DocType
- Font = ~Font
- SGML = ~SGML
- Heading = ~Heading
- Link = ~Link
- Meta = ~Meta
- Space = ~Space
- Ruler = ~Ruler
- Script = ~Script
- Table = ~Table
- end
-
- /* Compute arguments for RaiskaaHTML */
- raiskaa_options = ''
- if ~Blink then raiskaa_options = raiskaa_options || 'b'
- if ~Color then raiskaa_options = raiskaa_options || 'c'
- if ~DocType then raiskaa_options = raiskaa_options || 'd'
- if ~Font then raiskaa_options = raiskaa_options || 'f'
- if ~SGML then raiskaa_options = raiskaa_options || 'g'
- if ~Heading then raiskaa_options = raiskaa_options || 'h'
- if ~Link then raiskaa_options = raiskaa_options || 'l'
- if ~Meta then raiskaa_options = raiskaa_options || 'm'
- if ~Space then raiskaa_options = raiskaa_options || 'o'
- if ~Ruler then raiskaa_options = raiskaa_options || 'r'
- if ~Script then raiskaa_options = raiskaa_options || 's'
- if ~Table then raiskaa_options = raiskaa_options || 't'
-
- source_filename = From
- target_filename = to
-
- /* Convert possible URI to filename */
- source_filename = strip_from_begining(source_filename, 'file://localhost/')
- source_filename = strip_from_begining(source_filename, 'file:///')
-
- /* Check, if FROM argument denotes a directory */
- source_type = Word(StateF(source_filename), 1)
-
- if (source_type = 'FILE') then do
- /* Process a single file */
- Call raiskaa_file(source_filename, target_filename)
- end
- else do
- /* Process all files in a directory */
- if target_filename = '' then do
- Call status_message('scanning "' || source_filename || '" for documents')
- list_command = 'list >"' || list_filename || '" "' || source_filename || '" all pat=#?.(html|shtml|htm) lformat=%p%n'
- Address command list_command
- Call clear_status_message
-
- if Open('list_file', list_filename, 'read') then do
- do while ~Eof('list_file')
- Line = ReadLn('list_file')
- if (Line ~= '') then do
- Call raiskaa_file(line, '')
- end
- end
-
- Call Close('list_file')
- Delete(list_filename)
- end
- end
- else do
- Say error_in_arguments || 'option TO not allowed with FROM directory'
- return_code = 10
- end
- end
-
- /* Cleanup */
- Call Delete(temporary_filename)
- Delete(error_filename)
-
- exit return_code
-
- /* Format file size */
- format_size: Procedure
- Parse Arg size
-
- if Length(size) < 6 then do
- size = Right(size,6)
- end
-
- return size
-
- /* Send message to ScMsg message browser */
- send_scmsg:
- Parse Arg filename, line, class, number, text
- filename = AbsolutePath(filename)
- scmsg_command = 'NewMsg "' || filename || '" "' || filename ||'" ' || Strip(line,'B') || ' 0 "" 0 ' || Strip(class,'B') Strip(number,'B') Strip(text,'L')
- Address 'SC_SCMSG' scmsg_command
- Return
-
- /* Clear status message */
- clear_status_message:
- if ~Quiet then do
- WriteCh('STDOUT', Copies(' ', status_length+1) || d2c(13))
- end
- return
-
- /* Show status message */
- status_message:
- Parse Arg message
- if ~Quiet then do
- Call clear_status_message
- WriteCh('STDOUT', ' ' || message || d2c(13))
- status_length = Length(message)
- end
- return
-
- /* Strip string from begining if input starts with it */
- strip_from_begining: procedure
- Parse Arg source_text, strip_text
-
- strip_length = Length(strip_text)
- if Left(source_text, strip_length) = strip_text then do
- source_text = DelStr(source_text, 1, strip_length)
- end
-
- return source_text
-
- /* Raiskaa one file */
- raiskaa_file:
- Parse Arg source_filename, target_filename
-
- /* If no target specified, overwrite source */
- old_target_filename = target_filename;
- if target_filename = '' then do
- target_filename = source_filename;
- end
-
- /* Check for SAS/c message browser running; launch it if not */
- if ScMsg then do
- /* Invoke ScMsg, if it's not already there */
- if ~Show('ports', 'SC_SCMSG') then do
- Call status_message('invoking ScMsg')
- Address Command 'run <>nil: sc:c/scmsg HIDDEN'
- Address Command 'WaitForPort SC_SCMSG'
- end
-
- /* Check, if ScMsg showed up */
- if ~Show('ports', 'SC_SCMSG') then do
- Say "warning: could not start ScMsg, using console"
- ScMsg = 0
- end
- else do
- /* Remove old messages in ScMsg-window */
- Address 'SC_SCMSG' 'DelComp "' || AbsolutePath(source_filename) || '"'
- end
- end
-
- /* Remember size of source file */
- Call status_message(source_filename)
- if ~Quiet then do
- old_size = StateF(source_filename)
- Parse Var old_size . ' ' old_size .
- end
-
- /* Invoke TodellakinRaiskaaHTML */
- command_raiskaa = 'TodellakinRaiskaaHTML "' || raiskaa_options || '" "' || error_filename || '" <"' || source_filename || '" >' || temporary_filename
- Address Command command_raiskaa
- raiskaa_result = RC
-
- /* Handle errors */
- if raiskaa_result > 0 then do
-
- /* Update return code */
- if (raiskaa_result = 1) & (return_code < 5) then do
- return_code = 5
- end
- else if (raiskaa_result = 2) & (return_code < 10) then do
- return_code = 10
- end
- else do
- return_code = 20
- end
-
- /* Read error file and show it in ScMsg or console */
- if Open('error_file', error_filename, 'read') then do
-
- message_counter = 0
-
- do while ~Eof('error_file')
- message = ReadLn('error_file')
- if (message ~= '') then do
- message_counter = message_counter + 1
-
- /* Show message in console or browser */
- if ScMsg then do
- Parse Var message line ',' column ': ' class ':' text
- class = Upper(left(class,1)) || SubStr(class,2)
- Call send_scmsg(source_filename, line, class, 0, text)
- end
- else do
- WriteLn('STDOUT', source_filename || ':' || message)
- end
- end
- end
-
- /* Pop up message browser */
- if ScMsg & (message_counter > 0) then do
- Address 'SC_SCMSG' 'Show'
- end
-
- Call Close('error_file')
- end
- end
-
- if raiskaa_result < 2 then do
- /* Move temporary file to target */
- command_copy = 'copy quiet clone ' || temporary_filename || ' to "' || target_filename || '"'
- Address Command command_copy
-
- /* View raiskas report */
- if ~Quiet then do
- new_size = StateF(target_filename)
- Parse Var new_size . ' ' new_size .
-
- percent = 100
- if new_size > 0 then do
- percent = Trunc(100 - (new_size / old_size * 100), 1)
- end
-
- if Length(percent) > 3 then do
- percent = Trunc(percent,0)
- end
-
- Call clear_status_message
- Say 'Raiskattu: (' || Right(percent,3) || '%) ' || format_size(old_size) || ' => ' || format_size(new_size) || ': ' || source_filename
- end
- end
-
- /* Restore target filename */
- target_filename = old_target_filename;
-
- return raiskaa_result
-
-
-